//
//  HR_UMPush.m
//  Pods
//
//  Created by MAC on 2017/7/21.
//
//

#import "HR_UMPush.h"
#import "UMessage_Sdk_1.5.0a/UMessage.h"
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
#endif

@interface HR_UMPush ()<UNUserNotificationCenterDelegate>

@end

@implementation HR_UMPush
- (void)configUMPushWithAppkey:(NSString *)appKey launchOptions:(NSDictionary*)launchOptions {
    [UMessage startWithAppkey:appKey launchOptions:launchOptions httpsEnable:YES ];
    [UMessage openDebugMode:YES];
    //注册通知
    [UMessage registerForRemoteNotifications];
    //iOS10必须加下面这段代码。
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate=self;
    UNAuthorizationOptions types10=UNAuthorizationOptionBadge|UNAuthorizationOptionAlert|UNAuthorizationOptionSound;
    [center requestAuthorizationWithOptions:types10 completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if (granted) {
            //点击允许
            
        } else {
            //点击不允许
            
        }
    }];
}
#pragma mark -------- UNUserNotificationCenterDelegate --------
//iOS10新增：处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    if (self.delegate && [self.delegate respondsToSelector:@selector(hr_userNotificationCenter:willPresentNotification:withCompletionHandler:)]) {
        [self.delegate hr_userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
    }
}

//iOS10新增：处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
    if (self.delegate && [self.delegate respondsToSelector:@selector(hr_userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)]) {
        [self.delegate hr_userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
    }
}
@end
